import { utilJs } from "@/utils/common.js";
export function getBindPhoneSetting(ckFrom) {
  let bindPhoneSetting = {
    buyBind: false, // 购买前
    passwordBind: false, // 输入密码前
    getBind: false, // 获得前
    helpBind: false, // 助力前
    enrollBind: false, // 报名/投票前
    commentBind: false, // 评论前
    isVisitorBind: false, //游客模式需要绑定手机号的功能，（这个是对不需要绑定手机号的功能游客模式下绑定）
    shareBind: false, //邀请、分享前
    collectBind: false, //点赞、收藏、关注前
    rewardBind: false //打赏前
  };
  return new Promise(function (resolve, reject) {
    if (localStorage.getItem("isVisitor") && !!utilJs.getMobileBrowserType() && utilJs.getMobileBrowserType() != 'wx') {
      // 游客模式必须绑定手机号
      bindPhoneSetting = {
        buyBind: true,
        passwordBind: true,
        getBind: true,
        helpBind: true,
        enrollBind: true,
        commentBind: true,
        isVisitorBind: true,
        shareBind: true, //邀请、分享前
        collectBind: true, //点赞、收藏、关注前
        rewardBind: true //打赏前
      };
      resolve(bindPhoneSetting);
    } else if (localStorage.getItem("uMobile") && localStorage.getItem("uMobile") != undefined) { // 已有绑定手机号，就不请求接口了
      resolve(bindPhoneSetting);
    } else {
      utilJs.getMethod(`${global.apiurl}company/bindPhoneInstall?prodType=${ckFrom}`, res => {
        if (res && res.length > 0) {
          bindPhoneSetting.buyBind = res.filter((cv) => cv.type == 1).length > 0 && res.filter((cv) => cv.type == 1)[0].enableBind == 1 && (!localStorage.getItem("uMobile") || localStorage.getItem("uMobile") == undefined);
          bindPhoneSetting.passwordBind = res.filter((cv) => cv.type == 2).length > 0 && res.filter((cv) => cv.type == 2)[0].enableBind == 1 && (!localStorage.getItem("uMobile") || localStorage.getItem("uMobile") == undefined);
          bindPhoneSetting.getBind = res.filter((cv) => cv.type == 3).length > 0 && res.filter((cv) => cv.type == 3)[0].enableBind == 1 && (!localStorage.getItem("uMobile") || localStorage.getItem("uMobile") == undefined );
          bindPhoneSetting.helpBind = res.filter((cv) => cv.type == 4).length > 0 && res.filter((cv) => cv.type == 4)[0].enableBind == 1 && (!localStorage.getItem("uMobile") || localStorage.getItem("uMobile") == undefined );
          bindPhoneSetting.enrollBind = res.filter((cv) => cv.type == 5).length > 0 && res.filter((cv) => cv.type == 5)[0].enableBind == 1 && (!localStorage.getItem("uMobile") || localStorage.getItem("uMobile") == undefined );
          bindPhoneSetting.commentBind = res.filter((cv) => cv.type == 6).length > 0 && res.filter((cv) => cv.type == 6)[0].enableBind == 1 && (!localStorage.getItem("uMobile") || localStorage.getItem("uMobile") == undefined );
          bindPhoneSetting.shareBind = res.filter((cv) => cv.type == 7).length > 0 && res.filter((cv) => cv.type == 7)[0].enableBind == 1 && (!localStorage.getItem("uMobile") || localStorage.getItem("uMobile") == undefined );
          bindPhoneSetting.collectBind = res.filter((cv) => cv.type == 8).length > 0 && res.filter((cv) => cv.type == 8)[0].enableBind == 1 && (!localStorage.getItem("uMobile") || localStorage.getItem("uMobile") == undefined );
          bindPhoneSetting.rewardBind = res.filter((cv) => cv.type == 9).length > 0 && res.filter((cv) => cv.type == 9)[0].enableBind == 1 && (!localStorage.getItem("uMobile") || localStorage.getItem("uMobile") == undefined );
        }
        resolve(bindPhoneSetting);
      }, failRes => {
        reject(failRes)
      })
    }
  })
}